package cn.bdqn.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.bdqn.dao.appinfo.AppInfoDao;
import cn.bdqn.entity.AppInfo;
import cn.bdqn.service.AppInfoService;
import cn.bdqn.utils.PageBean;
@Service
@Transactional
public class AppInfoServiceImpl implements AppInfoService {
	
	@Autowired
	private AppInfoDao appInfoDao;

	
	
	
	@Override
	public PageBean<AppInfo> findAll(Map<String, Object> checkMap)  throws Exception{
		//1.当前页数.
		String currentPageStr = (String) checkMap.get("currentPage");
		Integer currentPage = currentPageStr != null ? Integer.valueOf(currentPageStr) : 1;
		//2.每个显示个数.
		String pageSizeStr = (String) checkMap.get("pageSize");
		Integer pageSize = pageSizeStr != null ? Integer.valueOf(pageSizeStr) : 5;
		//3.app的总条数
		Integer totalCount = appInfoDao.findAppInfoCount(checkMap);
		
		//4.创建 PageBean<AppInfo>
		PageBean<AppInfo> pageBean = new PageBean<>(currentPage, pageSize, totalCount);
		 
		//5.查询APP商品信息
		Integer startIndex = pageBean.getStartIndex();
		Integer pageSize2 = pageBean.getPageSize();
		checkMap.put("startIndex", startIndex);
		checkMap.put("pageSize", pageSize2);
		List<AppInfo> appInfoList = appInfoDao.findAll(checkMap);
		
		//6.封装数据
		pageBean.setPageList(appInfoList);
		
		
		return pageBean;
	}




	@Override
	public Integer save(AppInfo appInfo) throws Exception {
		return appInfoDao.save(appInfo);
	}




	@Override
	public Integer findAppInfoByApkname(String apkname) throws Exception {
		AppInfo appInfo = appInfoDao.findAppInfoByApkname(apkname);
		if(appInfo == null){
			//可以使用
			return 0;
		}else{
			return 1;
		}
	}




	@Override
	public AppInfo findAppInfoById(Integer id) throws Exception {
		return appInfoDao.findAppInfoById(id);
	}




	@Override
	public Integer update(AppInfo appInfo) throws Exception {
		// TODO Auto-generated method stub
		return appInfoDao.update(appInfo);
	}




	@Override
	public String findAppInfoPicpathById(Long id) throws Exception {
		return appInfoDao.findAppInfoPicpathById(id);
	}




	@Override
	public String findAPKNameById(Long appid) throws Exception {
		return appInfoDao.findAPKNameById(appid);
	}




	@Override
	public int delAppInfo(Integer appid) throws Exception {
		// TODO Auto-generated method stub
		return appInfoDao.delAppInfo(appid);
	}




	@Override
	public int updatestatus(Long status, Long id) throws Exception {
		
		return appInfoDao.updatestatus(status,id);
	}




	@Override
	public Integer updateAppStatusName(Long id) throws Exception {
		// TODO Auto-generated method stub
		return appInfoDao.updateAppStatusName(id);
	}




	@Override
	public Integer updateAppStatusNameDown(Long id) throws Exception {
		// TODO Auto-generated method stub
		return appInfoDao.updateAppStatusNameDown(id);
	}
	
}
